package com.toolbox.alui.common.helpers;

import com.plumtree.openlog.OpenLogService;
import com.plumtree.openlog.OpenLogger;
import com.plumtree.portalpages.browsing.gateway.GatewayModel;
import com.plumtree.portalpages.common.uiparts.NavigationModel;
import com.plumtree.portaluiinfrastructure.statichelpers.PTDebugHelpers;
import com.plumtree.server.IPTMigrationManager;
import com.plumtree.server.IPTSession;
import com.plumtree.server.PT_GLOBALOBJECTS;
import com.plumtree.taskapi.portalui.TaskAPIUICommon;
import com.plumtree.taskapi.portalui.TaskAPIUICommunity;
import com.plumtree.taskapi.portalui.TaskAPIUIMyPages;
import com.plumtree.taskapi.server.TaskAPIServerCommon;
import com.plumtree.uiinfrastructure.activityspace.AActivitySpace;

public class ServerHelper {
	private static OpenLogger log = OpenLogService.GetLogger(
			OpenLogService.GetComponent(PTDebugHelpers.COMPONENT_PORTAL_UI_INFRASTRUCTURE),
			"com.toolbox.alui.common.helpers.ServerHelper");
	
	public AActivitySpace m_asOwner = null;
	public IPTSession oPTSession = null;
	
	public ServerHelper(AActivitySpace asOwner) {
		m_asOwner = asOwner;
		oPTSession = (IPTSession)asOwner.GetUserSession();
	}
	
	public int getUserID(){
		return oPTSession.GetUser().GetObjectID();
	}
	
	public int getObjectID(String uuid){
		if (null != uuid) {
			Object[] oClassIDObjectID = getClassObjectID(uuid);
			if(null != oClassIDObjectID){
				try{
					return Integer.parseInt(oClassIDObjectID[1].toString());
				} catch (Exception exc){
					return 0;
				}
			}
		}
		return 0;
	}
	
	public int getClassID(String uuid){
		if (null != uuid) {
			Object[] oClassIDObjectID = getClassObjectID(uuid);
			if(null != oClassIDObjectID){
				try{
					return Integer.parseInt(oClassIDObjectID[0].toString());
				} catch (Exception exc){
					return 0;
				}
			}
		}
		return 0;
	}
	
	public Object[] getClassObjectID(String uuid){
		Object[] oClassIDObjectID = null;
		if (null != uuid) {
			try {
				IPTMigrationManager oPTMigrationMgr = (IPTMigrationManager) oPTSession
						.OpenGlobalObject(
								PT_GLOBALOBJECTS.PT_GLOBAL_MIGRATION_MANAGER,
								false);
				oClassIDObjectID = oPTMigrationMgr.UUIDToObjectID(uuid);
			} catch (Exception exc) {
				oClassIDObjectID = null;
			}
		}
		return oClassIDObjectID;
	}
}
